using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.IO;
using yW5Lib;

namespace yWriter6
{
	public class clsExportToText
	{
		public void ExportToText(clsProject cProject)
		{
			//Discarded unreachable code: IL_017e, IL_01bd, IL_01c8, IL_01d8, IL_0266, IL_0268, IL_027c, IL_029e
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				new Collection();
				num2 = 3;
				string outputFilename = clsShared.cFileSel.GetOutputFilename("Specify a .TXT file to export to", cProject.ProjectPath(), "Exported Project.txt", "*.txt", !clsShared.cSettings.sGet("OverwriteExport", DefaultIfUnknown: false));
				num2 = 4;
				if (Operators.CompareString(outputFilename, "", TextCompare: false) != 0)
				{
					num2 = 5;
					int num3 = (int)clsShared.cLang.TransMsgBox("Save summaries to file as well?", MsgBoxStyle.YesNo);
					num2 = 6;
					bool saveSummaries;
					if (num3 == 6)
					{
						num2 = 7;
						saveSummaries = true;
					}
					else
					{
						num2 = 9;
						saveSummaries = false;
					}
					num2 = 10;
					num3 = (int)clsShared.cLang.TransMsgBox("Include unused chapters and scenes?", MsgBoxStyle.YesNo);
					num2 = 11;
					bool saveUnused;
					if (num3 == 6)
					{
						num2 = 12;
						saveUnused = true;
					}
					else
					{
						num2 = 14;
						saveUnused = false;
					}
					num2 = 15;
					StreamWriter streamWriter = clsShared.cFile.OpenOutputStream(outputFilename);
					num2 = 16;
					if (streamWriter != null)
					{
						num2 = 17;
						streamWriter.WriteLine("   Formatting instructions (delete these lines)");
						num2 = 18;
						streamWriter.WriteLine("--------------------------------------------------");
						num2 = 19;
						streamWriter.WriteLine("Replace [PB] with ^m");
						num2 = 20;
						streamWriter.WriteLine("Replace <center> with center formatting");
						num2 = 21;
						streamWriter.WriteLine("Autoformat to convert *bold* and _italic_ text (e.g. chapter headings)");
						num2 = 22;
						streamWriter.WriteLine("--------------------------------------------------");
						num2 = 23;
						streamWriter.WriteLine("");
						num2 = 24;
						streamWriter.WriteLine("");
						num2 = 25;
						streamWriter.WriteLine("");
						num2 = 26;
						streamWriter.WriteLine(cProject.ExportAsText(saveSummaries, saveUnused));
						num2 = 27;
						streamWriter.Close();
						num2 = 28;
						clsShared.cFile.RunFile(cProject.ProjectPath());
					}
				}
			}
			catch (Exception obj) when ((num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError(obj);
				/*Error near IL_029c: Could not find block for branch target IL_0268*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
